﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TjZheng.CMS.Process;
using TjZheng.CMS.Process.Business;
using TjZheng.Framework;
using TjZheng.Power.Business;
using TjZheng.Power.DataEntity;

namespace TjZheng.CMS.Controllers
{
    public class HomeController : CMSController
    {
        [AuthorizeFilter(PowerType.CheckLogin)]
        public ActionResult Index()
        {
            return View();
        }
        [ChildActionOnly]
        public ActionResult ColumnPowerInfoList()
        {
            BizPowerInfo objBizPowerInfo = new BizPowerInfo();
            return View(objBizPowerInfo.GetList("ParentId=1", "SortIndex asc"));
        }
        [ChildActionOnly]
        public ActionResult UserColumnPowerInfoList()
        {
            //读取用户权限
            UserProcess objUserProcess = new UserProcess();
            var objUserPowerType = objUserProcess.ConvertoUserPowerType(CurrentUser.PowerType);
            if (!objUserPowerType.HasValue)
            {
                return Content("<!--对不起，访问权限类型异常-->");
            }
            return View(objUserProcess.GetUserColumnPowerInfoList(CurrentUser.Id, objUserPowerType.Value));
        }

        [AuthorizeFilter(PowerType.None)]
        public ActionResult UserLogin()
        {
            UserProcess objUserProcess = new UserProcess();
            if (objUserProcess.CheckOnLogin() && objUserProcess.CheckLogin())
            {
                return Redirect("/");
            }
            return View();
        }
        [AuthorizeFilter(PowerType.None)]
        public ActionResult Login(string userName, string password)
        {
            UserProcess objUserProcess = new UserProcess();
            return Json(objUserProcess.Login(userName, password), "text/plain");
        }
        [AuthorizeFilter(PowerType.None)]
        public ActionResult LoginOut()
        {
            UserProcess objUserProcess = new UserProcess();
            objUserProcess.LoginOut();
            return Redirect("/home/userlogin");
        }
    }
}
